#!/usr/bin/env python

import sys, re, urllib, bz2
import binascii

server_name = 'www.pythonchallenge.com'
file_name = '/pc/def/linkedlist.php?busynothing='
number = 12345
info = ''

time = 0
while time < 1000:
    print 'No.', time
    remote_addr = 'http://%s%s%d' %(server_name, file_name, number)
    print 'Open', remote_addr
    request = urllib.urlopen(remote_addr)
    mo = re.search('info=([^;]+);', ''.join(request.info().headers))
    cur = mo.group(1)
    print 'current info:', cur
    info += cur
    text = ''.join(request.readlines())
    print 'Content:', text
    mo = re.search('and the next busynothing is (\d+)', text)
    if mo == None:
        break
    number = int(mo.group(1))
    time += 1
print info
print bz2.decompress(urllib.unquote_plus(info))

